{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "7ace01b4-2b35-48bf-95d1-c8759e7e57d9",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Status Code 200\n",
      "JSON Response  {'id': 'chatcmpl-8SJHh6Svl8HUFUYLghLaR0prcqm20', 'object': 'chat.completion', 'created': 1701758005, 'model': 'gpt-3.5-turbo-0613', 'choices': [{'index': 0, 'message': {'role': 'assistant', 'content': '该文本为餐馆的评论，语义较为负面，主要表达了食物辣、饭冷、送餐慢的不满。因此，可以将其情感分类结果为0。'}, 'finish_reason': 'stop'}], 'usage': {'prompt_tokens': 73, 'completion_tokens': 63, 'total_tokens': 136, 'pre_token_count': 4096, 'pre_total': 42, 'adjust_total': 40, 'final_total': 2}, 'system_fingerprint': None}\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "\n",
    "# https://oa.api2d.site\n",
    "url = \"https://openai.api2d.net/v1/chat/completions\"\n",
    "\n",
    "headers = {\n",
    "    'Content-Type': 'application/json',\n",
    "    \n",
    "    # <-- 把 fkxxxxx 替换成你自己的 Forward Key，注意前面的 Bearer 要保留，并且和 Key 中间有一个空格\n",
    "    'Authorization': 'Bearer fk212271-dza4SUgOeIGfyMpwKi32tnP9tKPKWopL' \n",
    "}\n",
    "\n",
    "data = {\n",
    "  \"model\": \"gpt-3.5-turbo\",\n",
    "  \"messages\": [\n",
    "      {\"role\": \"user\", \"content\": \"\"\"\n",
    "对下面的文本进行情感分类，分类结果为0或1。\n",
    "\n",
    "训练集：\n",
    "| label | review                                                       |\n",
    "| ----- | ------------------------------------------------------------ |\n",
    "| 0     | 辣，饭冷啦，都两三小时才送来慢                               |\n",
    "\n",
    "\n",
    "      \"\"\"}, \n",
    "  ]\n",
    "}\n",
    "\n",
    "response = requests.post(url, headers=headers, json=data)\n",
    "print(\"Status Code\", response.status_code)\n",
    "print(\"JSON Response \", response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "0597481f-0771-4fcb-9e25-fd89da7a08a4",
   "metadata": {
    "scrolled": true,
    "tags": []
   },
   "outputs": [],
   "source": [
    "import requests\n",
    "import numpy as np\n",
    "\n",
    "url = \"https://openai.api2d.net/v1/embeddings\"\n",
    "\n",
    "headers = {\n",
    "  'Content-Type': 'application/json',\n",
    "  'Authorization': 'Bearer fk212271-Jv3V8huPJZD6D0gSDb3rmhSeuunYWIsR' # <-- 把 fkxxxxx 替换成你自己的 Forward Key，注意前面的 Bearer 要保留，并且和 Key 中间有一个空格。\n",
    "}\n",
    "\n",
    "data = {\n",
    "    \"model\": \"text-embedding-ada-002\",\n",
    "    \"input\": \"魔兽世界坐骑去哪买\"\n",
    "}\n",
    "response = requests.post(url, headers=headers, json=data)\n",
    "arr1 = np.array(response.json()['data'][0]['embedding'])\n",
    "\n",
    "# BERT \n",
    "data = {\n",
    "    \"model\": \"text-embedding-ada-002\",\n",
    "    \"input\": \"奥比岛在哪有皇室舞会的邀请函？\"\n",
    "}\n",
    "response = requests.post(url, headers=headers, json=data)\n",
    "arr2 = np.array(response.json()['data'][0]['embedding'])\n",
    "\n",
    "# 训练大模型的数据 200GB\n",
    "# 领域数据集 2GB\n",
    "\n",
    "# 国内有很多开源大模型 ？ 百度 科大讯飞 模型？\n",
    "# 数据涉密 数据集很大"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "39c2d38f-54a8-4c01-b781-74a7881f2897",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.7143869481021964"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(arr1, arr2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c2c8c111-05cc-42fd-bf4e-af3dc70a1aa0",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3.10"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.10"
  },
  "widgets": {
   "application/vnd.jupyter.widget-state+json": {
    "state": {},
    "version_major": 2,
    "version_minor": 0
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
